<?php
/**
 * Exception
 * 
 * @category	XML
 * @package		dayscript.xml.rpc
 * @subpackage	
 * @author		Nelson Daza <ndaza@dayscript.com>
 * @copyright	2009 Dayscript Ltda.
 * @license		
 * @version		1.0
 * @version		$Revision: 0 $
 * @filesource	
 * @link		http://www.dayscript.com
 * @link		{docsLink}
 * @uses		
 * @since		1.0
 * @modifiedby	$LastChangedBy: Nelson Daza $
 * @modified	$Date: 2009-08-13 $
 */

namespace dayscript\xml\rpc;

/**
 * Exception
 *
 * @category	XML
 * @package		dayscript.xml.rpc
 * @subpackage	
 * @author		Nelson Daza <ndaza@dayscript.com>
 * @copyright	2009 Dayscript Ltda.
 * @license		
 * @version		1.0
 * @link		http://www.dayscript.com
 * @link		{docsLink}
 * @uses		\dayscript\exception\Exception, \dayscript\log\LogManager
 * @since		1.0
 * @modifiedby	$LastChangedBy: Nelson Daza $
 * @modified	$Date: 2009-08-13 $
 */
class Exception extends \dayscript\exception\Exception	{
	/**
	 * RPC Error code 
	 * @var int $RPCCode
	 */
	private $RPCCode;
	/**
	 * Exception Contructor
	 *
	 * @param string $message
	 * @param int $RPCCode
	 * @return \dayscript\exception\Exception
	 */
	public function __construct( $message = null, $RPCCode = \E_UNKNOWN )	{
		$this->RPCCode = $RPCCode;
		parent::__construct( $message, \E_USER_ERROR );
	}
	/**
	 * Returns RPCCode 
	 * @return int $RPCCode
	 */
	function getRPCCode( )	{
		return \strlen( $this->RPCCode );
	}
	/**
	 * Returns XML representation of Exception
	 * @return string $xml
	 */
	function getXML( )	{
		$xml = '<methodResponse><fault><value><struct>' . 
			'<member><name>faultCode</name><value><int>' . $this->RPCCode . '</int></value></member>' . 
			'<member><name>faultString</name><value><string>' . $this->getMessage( ) . '</string></value></member>';
		if( \dayscript\log\LogManager::canLog( \dayscript\log\LogManager::LOG_DATASOURCE ) )
			$xml .= '<member><name>faultStackTrace</name><value><string>' . $this->getTraceAsString( ) . '</string></value></member>';
		$xml .= '</struct></value></fault></methodResponse>';
		
		return $xml;
	}

}
